package com.example.oms.controller;

import com.example.oms.entity.Meds;
import com.example.oms.service.PharmacyService;
import com.example.oms.vo.PrescriptionAndMedListVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PharmacyController {
    @Resource
    private PharmacyService pharmacyService;

    @PostMapping("/drugManagement/addStock")
    public ResponseEntity<String> addStock(@RequestBody Map<String,Integer>map){
        pharmacyService.addStock(map.get("id"));
        return ResponseEntity.ok("ok");
    }

    @PostMapping("/drugManagement/clearStock")
    public ResponseEntity<String> clearStock(@RequestBody Map<String,Integer>map){
        pharmacyService.clearStock(map.get("id"));
        return ResponseEntity.ok("ok");
    }

    @GetMapping("/drugManagement/getAllDrugs")
    public ResponseEntity<Map<String, List<Meds>>> getAllDrugs(){
        List<Meds> allDrugs = pharmacyService.getAllDrugs();
        Map<String, List<Meds>> map = new HashMap<>();
        map.put("drugs",allDrugs);
        return ResponseEntity.ok(map);
    }

    @GetMapping("/Prescription/getAllPrescription")
    public ResponseEntity<Map<String, List<PrescriptionAndMedListVo>>> getAllPrescription(){
        List<PrescriptionAndMedListVo> allPrescription = pharmacyService.getAllPrescription();
        Map<String, List<PrescriptionAndMedListVo>> map = new HashMap<>();
        map.put("items",allPrescription);
        return ResponseEntity.ok(map);
    }

    @PostMapping("/Prescription/Distribute")
    public ResponseEntity<String> Distribute(@RequestBody Map<String,Integer>map){
        System.out.println(map);
        pharmacyService.Distribute(map.get("prescription_id"));
        return ResponseEntity.ok("ok");
    }

    @PostMapping("/Prescription/withdrawDrugs")
    public ResponseEntity<String> withdrawDrugs(@RequestBody Map<String,Integer>map){
        System.out.println(map);
        pharmacyService.withdrawDrugs(map.get("prescription_id"));
        return ResponseEntity.ok("ok");
    }
}
